package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jack
 * @data 2024 9:12
 */
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;


    /**
     * 新增频道
     *
     * @param wmChannel WM通道
     * @return {@link ResponseResult}
     */
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody WmChannel wmChannel){
        return wmChannelService.insert(wmChannel);
    }

    /**
     * 按名称查询页面
     *
     * @param channelDto 通道 DTO
     * @return {@link ResponseResult}
     */
    @PostMapping("/list")
    public ResponseResult pageQueryByName(@RequestBody ChannelDto channelDto){
        return wmChannelService.pageQueryByName(channelDto);
    }

    /**
     * 修改频道
     *
     * @param wmChannel WM通道
     * @return {@link ResponseResult}
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        return wmChannelService.update(wmChannel);
    }

    /**
     * 按 ID 删除
     *
     * @param id 编号
     * @return {@link ResponseResult}
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        return wmChannelService.deleteById(id);
    }
}
